package com.yanqu.road.server.cmd.activity.jinli;

import com.yanqu.road.entity.player.UserBaseInfo;
import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.JinLiProto;
import com.yanqu.road.pb.player.PlayerProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.manager.activity.jinli.CrossJinLiActivity;
import com.yanqu.road.server.manager.activity.jinli.CrossJinLiMgr;
import com.yanqu.road.server.manager.user.CrossUserMgr;
import com.yanqu.road.server.protocol.CrossProtocol;

/**
 * 添加锦鲤
 */
@Cmd(code = CrossProtocol.C_CROSS_JINLI_ADD, desc = "添加锦鲤")
public class CrossJinLiAddCmd extends CrossCommand {

    private int activityId;
    private int mallId;

    private PlayerProto.PlayerBaseTempMsg playerInfo;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        JinLiProto.CrossAddJinLiReqMsg reqMsg = JinLiProto.CrossAddJinLiReqMsg.parseFrom(packet.getBytes());
        activityId = reqMsg.getActivityId();
        mallId = reqMsg.getMallId();
        playerInfo = reqMsg.getPlayerInfo();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        CrossJinLiActivity activity = CrossJinLiMgr.getActivity(activityId);
        if (activity == null) {
            return;
        }
        // 更新userBaseInfo
        UserBaseInfo userBaseInfo = PlayerBasePb.parseBaseUserInfo(playerInfo);
        CrossUserMgr.updateUserBaseInfo(packet.getPlayerId(), userBaseInfo);

        // 添加锦鲤
        activity.addJinLi(serverId, packet.getPlayerId(), mallId);
    }

    @Override
    public void sendData() {

    }
}
